﻿using NetROS.Tiers.Entities;
using NetROS.Tiers.Services;

namespace NetRosApp.Klijenti
{
    public class BaseTraziPresenter<T> : Infrastructure.Interface.Base.BaseViews.BaseTraziPresenter<T>, IBaseTraziPresenter where T : IBaseTraziView
    {

        //[EventSubscription(EventTopicNames.EntityItemChanged, ThreadOption.Publisher)]
        //public void OnEntityItemChanged(object sender, EventArgs<object, string> eventArgs)
        //{//TODO: Add your code here
        //    if (eventArgs.Data1 == "Entity")
        //    {
        //        SetEntity(eventArgs.Data);
        //    }
        //}

        //protected internal virtual void SetEntity(object Entity)
        //{
        //    WorkItem.Services.Get<IExpUtil>().HandleException(new Exception("Nedefinirani način. SetEntity"));
        //}

      

        //public virtual void OnCloseView()
        //{
        //    try
        //    {
        //        if (WorkItem.Workspaces[WorkspaceNames.RightWorkspace].ActiveSmartPart == View.SmartPartView)
        //        {
        //            int index = WorkItem.Workspaces[WorkspaceNames.RightWorkspace].SmartParts.IndexOf(WorkItem.Workspaces[WorkspaceNames.RightWorkspace].ActiveSmartPart);
        //            if (index - 1 >= 0)
        //            {
        //                WorkItem.Workspaces[WorkspaceNames.RightWorkspace].Activate(WorkItem.Workspaces[WorkspaceNames.RightWorkspace].SmartParts[index - 1]);
        //            }
        //        }
        //    }
        //    catch
        //    {
        //    }

        //    base.CloseView();
            
        //    try
        //    {
        //        //WorkItem.Items.Remove(this.View);
        //        //WorkItem.Items.Remove(this);
            
                
        //        WorkItem.Terminate();
        //    }
        //    catch { }
        //}

        //#region Base Subscriptions
        //[EventSubscription(EventTopicNames.CloseActiveViewInRightWorkspace, ThreadOption.UserInterface)]
        //public void OnCloseActiveViewInRightWorkspace(object sender, EventArgs<bool, object> eventArgs)
        //{//TODO: Add your code here
        //    if (eventArgs.Data || View.IsFocused() || object.Equals(eventArgs.Data1, View))
        //    {
        //        OnCloseView();
        //    }
        //}

        //#endregion

        //public void OpenEditorNewOrEditinParent(object Entity)
        //{
        //    WorkItem.EventTopics[EventTopicNames.OpenCreateView].Fire(this.View, new EventArgs<object, object, object, object, WorkItem>(null, Entity, null, 1, WorkItem.Parent), WorkItem, PublicationScope.Global);
        //}

        //public void OpenEditorNewOrEditinTab(object Entity, Type EditorClass)
        //{
        //    WorkItem.EventTopics[EventTopicNames.OpenCreateView].Fire(this.View, new EventArgs<object, object, object, object, WorkItem>(EditorClass, Entity, null, null, WorkItem.Parent), WorkItem, PublicationScope.Global);
        //}


        //public void OpenEditorNewOrEditinParent(object Entity)
        //{
        //    WorkItem.EventTopics[EventTopicNames.OpenCreateView].Fire(this.View, new EventArgs<object, object, object, object, WorkItem>(null, Entity, null, null, WorkItem.Parent), WorkItem, PublicationScope.Global);
        //}

        //public void OpenEditorNewOrEditinTab(object Entity, Type EditorClass)
        //{
        //    WorkItem.EventTopics[EventTopicNames.OpenCreateView].Fire(this.View, new EventArgs<object, object, object, object, WorkItem>(EditorClass, Entity, null, null, null), WorkItem, PublicationScope.Global);
        //}


        //public void OpenEditorNewModal(Type EditorClass)
        //{
        //    WindowSmartPartInfo wspi = new WindowSmartPartInfo();
        //    wspi.Modal = true;
        //    WorkItem.EventTopics[EventTopicNames.OpenCreateViewModal].Fire(this, new EventArgs<WorkItem, object, object, WindowSmartPartInfo, object>(WorkItem, EditorClass, null, wspi, null), WorkItem, PublicationScope.Global);
        //}

        //public override void OnViewReady()
        //{
        //    base.OnViewReady();
        //    WorkItem.EventTopics.Get(EventTopicNames.StatusUpdate).Fire(this, new EventArgs<string>("Ready"), WorkItem, PublicationScope.Global);
        //}

        private DokumentService _dokumentService;
        internal Dokument GetHasStorno(Dokument Entity, int StornoTip)
        {
            if (Entity != null)
            {
                if (_dokumentService == null)
                    _dokumentService = WorkItem.Services.Get<DokumentService>();

                TList<Dokument> TlStorno = _dokumentService.GetHasStorno(Entity.ID, StornoTip);
                if (TlStorno.Count == 0)
                {
                    return null;
                }
                else
                {
                    return TlStorno[0];
                }
            }
            return null;
        }

        readonly BaseOtvaranjeIzvjestaja _tmpReportOpen = new BaseOtvaranjeIzvjestaja();
        public void ShowReportForDokumentTip(object sender,Dokument _entity)
        {
            _tmpReportOpen.ShowReportForDokumentTip("BaseTrazi",_entity, WorkItem);
        }


        //public void ShowReportForDokumentTip(Dokument _entity)
        //{

        //    DevExpress.XtraReports.UI.XtraReport report;
        //    if (_entity == null) return;
        //    if (_entity.ID == 0)
        //    {
        //        return;
        //    }
        //    ReportSelectorFrm _tmpfrm = new ReportSelectorFrm();
        //    System.Collections.ArrayList _tmpList = new System.Collections.ArrayList();
        //    switch (_entity.IDDokumentTip)
        //    {
        //        case (int)DokumentTipList.Međuskladišnica_Izdana_Robno:
        //            report = new MeduskladisnicaIspis(_entity);
        //            WorkItem.EventTopics[EventTopicNames.PrikaziIzvjestaj].Fire(this, new EventArgs<object, string>(report, String.Format("Međuskladišnica {0}", _entity.Oznaka)), WorkItem, PublicationScope.Global);
        //            break;
        //        case (int)DokumentTipList.Međuskladišnica_Izdana_Storno:
        //            report = new MeduskladisnicaStornoIspis(_entity);
        //            WorkItem.EventTopics[EventTopicNames.PrikaziIzvjestaj].Fire(this, new EventArgs<object, string>(report, String.Format("Međuskladišnica storno {0}", _entity.Oznaka)), WorkItem, PublicationScope.Global);
        //            break;
        //        case (int)DokumentTipList.Međuskladišnica_Primljena_Robno:
        //            report = new MeduskladisnicaPrijemIspis(_entity);
        //            WorkItem.EventTopics[EventTopicNames.PrikaziIzvjestaj].Fire(this, new EventArgs<object, string>(report, String.Format("Međuskladišnica prijem {0}", _entity.Oznaka)), WorkItem, PublicationScope.Global);
        //            break;
        //        case (int)DokumentTipList.Međuskladišnica_prijem_Storno:
        //            report = new MeduskladisnicaPrijemStornoIspis(_entity);
        //            WorkItem.EventTopics[EventTopicNames.PrikaziIzvjestaj].Fire(this, new EventArgs<object, string>(report, String.Format("Međuskladišnica prijem storno {0}", _entity.Oznaka)), WorkItem, PublicationScope.Global);
        //            break;
        //        case (int)DokumentTipList.Narudžba:
        //            _tmpfrm = new ReportSelectorFrm();
        //            //  Dictionary<int, String> _tmpdict = new Dictionary<int, String>();
        //          _tmpList = new System.Collections.ArrayList();
        //            //_tmpdict.Add(1, "Prijemni list storno");
        //            //_tmpdict.Add(0, "Povrat robe");
        //            _tmpList.Add("Narudžbenica s cijenom");
        //            _tmpList.Add("Narudžbenica");
        //            _tmpfrm.LBIzabir.DataSource = _tmpList;
        //            _tmpfrm.LBIzabir.SelectedIndex = 0;
        //            //_tmpfrm.LBIzabir.DisplayMember("Value");
        //            if (_tmpfrm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
        //            {
        //                if (_tmpfrm.LBIzabir.SelectedItem.ToString() == "Narudžbenica")
        //                {
        //                    report = new NarudzbenicaIspis(_entity);
        //                    WorkItem.EventTopics[EventTopicNames.PrikaziIzvjestaj].Fire(this, new EventArgs<object, string>(report, String.Format("Narudžbenica {0}", _entity.Oznaka)), WorkItem, PublicationScope.Global);
        //                }
        //                if (_tmpfrm.LBIzabir.SelectedItem.ToString() == "Narudžbenica s cijenom")
        //                {

        //                    report = new NarudzbenicaIspis2(_entity);
        //                    WorkItem.EventTopics[EventTopicNames.PrikaziIzvjestaj].Fire(this, new EventArgs<object, string>(report, String.Format("Narudžbenica {0}", _entity.Oznaka)), WorkItem, PublicationScope.Global);


        //                }

        //            }

                   
        //            break;
        //        case (int)DokumentTipList.Otkaz_rezervacije:
        //            //EditorClass = typeof(RezervacijaView);
        //            break;
        //        case (int)DokumentTipList.Otpremnica:
        //            _tmpfrm = new ReportSelectorFrm();
        //            //  Dictionary<int, String> _tmpdict = new Dictionary<int, String>();
        //            _tmpList = new System.Collections.ArrayList();
        //            //_tmpdict.Add(1, "Prijemni list storno");
        //            //_tmpdict.Add(0, "Povrat robe");
        //            _tmpList.Add("Otpremnica");
        //            _tmpList.Add("Otpremnica s cijenom");
        //            _tmpfrm.LBIzabir.DataSource = _tmpList;
        //            _tmpfrm.LBIzabir.SelectedIndex = 0;
        //            //_tmpfrm.LBIzabir.DisplayMember("Value");
        //            if (_tmpfrm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
        //            {
        //                if (_tmpfrm.LBIzabir.SelectedItem.ToString() == "Otpremnica")
        //                {
        //                    report = new OtpremnicaIspis(_entity);
        //                    WorkItem.EventTopics[EventTopicNames.PrikaziIzvjestaj].Fire(this, new EventArgs<object, string>(report, String.Format("Otpremnica {0}", _entity.Oznaka)), WorkItem, PublicationScope.Global);
        //                }
        //                if (_tmpfrm.LBIzabir.SelectedItem.ToString() == "Otpremnica s cijenom")
        //                {

        //                    report = new OtpremnicaIspisKol(_entity);
        //                    WorkItem.EventTopics[EventTopicNames.PrikaziIzvjestaj].Fire(this, new EventArgs<object, string>(report, String.Format("Otpremnica {0}", _entity.Oznaka)), WorkItem, PublicationScope.Global);

        //                }

        //            }

        //            break;
        //        case (int)DokumentTipList.Otpremnica_Storno:
        //            _tmpfrm = new ReportSelectorFrm();
        //            //  Dictionary<int, String> _tmpdict = new Dictionary<int, String>();
        //            _tmpList = new System.Collections.ArrayList();
        //            //_tmpdict.Add(1, "Prijemni list storno");
        //            //_tmpdict.Add(0, "Povrat robe");
        //            _tmpList.Add("Otpremnica");
        //            _tmpList.Add("Otpremnica s cijenom");
        //            _tmpfrm.LBIzabir.DataSource = _tmpList;
        //            _tmpfrm.LBIzabir.SelectedIndex = 0;
        //            //_tmpfrm.LBIzabir.DisplayMember("Value");
        //            if (_tmpfrm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
        //            {
        //                if (_tmpfrm.LBIzabir.SelectedItem.ToString() == "Otpremnica")
        //                {

        //                    report = new OtpremnicaIspisStorno(_entity);
        //                    WorkItem.EventTopics[EventTopicNames.PrikaziIzvjestaj].Fire(this, new EventArgs<object, string>(report, String.Format("Otpremnica storno {0}", _entity.Oznaka)), WorkItem, PublicationScope.Global);
        //                }
        //                if (_tmpfrm.LBIzabir.SelectedItem.ToString() == "Otpremnica s cijenom")
        //                {


        //                    report = new OtpremnicaIspisKolStorno(_entity);
        //                    WorkItem.EventTopics[EventTopicNames.PrikaziIzvjestaj].Fire(this, new EventArgs<object, string>(report, String.Format("Otpremnica storno {0}", _entity.Oznaka)), WorkItem, PublicationScope.Global);
        //                }

        //            }

        //            break;
              
        //        case (int)DokumentTipList.Početno_stanje:
        //            report = new Pocetnostanje(_entity);
        //            WorkItem.EventTopics[EventTopicNames.PrikaziIzvjestaj].Fire(this, new EventArgs<object, string>(report, String.Format("Početno stanje{0}", _entity.Oznaka)), WorkItem, PublicationScope.Global);
        //            break;
        //        case (int)DokumentTipList.Početno_stanje_storno:
        //            break;
        //        case (int)DokumentTipList.Prijemni_list:
        //            if (_entity.IDValute == 1 || _entity.IDValute == null)
        //            {
        //                report = new PrijemniList(_entity);
                        
        //            }
        //            else
        //            {
        //                report = new PrijemniListValuti(_entity);
        //            }
        //            WorkItem.EventTopics[EventTopicNames.PrikaziIzvjestaj].Fire(this, new EventArgs<object, string>(report, String.Format("Prijemni list {0}", _entity.Oznaka)), WorkItem, PublicationScope.Global);
        //            break;
        //        case (int)DokumentTipList.Prijemni_list_Storno:
        //             _tmpfrm = new ReportSelectorFrm();
        //            //  Dictionary<int, String> _tmpdict = new Dictionary<int, String>();
        //             _tmpList = new System.Collections.ArrayList();
        //            //_tmpdict.Add(1, "Prijemni list storno");
        //            //_tmpdict.Add(0, "Povrat robe");
        //            _tmpList.Add("Prijemni list strono");
        //            _tmpList.Add("Povrat robe");
        //            _tmpfrm.LBIzabir.DataSource = _tmpList;
        //            _tmpfrm.LBIzabir.SelectedIndex = 0;
        //            //_tmpfrm.LBIzabir.DisplayMember("Value");
        //            if (_tmpfrm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
        //            {
        //                if (_tmpfrm.LBIzabir.SelectedItem.ToString() == "Prijemni list strono")
        //                {
        //                    if (_entity.IDValute == 1 || _entity.IDValute == null)
        //                    {
        //                        report = new PrijemniListStorno(_entity);

        //                    }
        //                    else
        //                    {
        //                        report = new PrijemniListValutiStorno(_entity);
        //                    }
        //                    WorkItem.EventTopics[EventTopicNames.PrikaziIzvjestaj].Fire(this, new EventArgs<object, string>(report, String.Format("Prijemni list {0}", _entity.Oznaka)), WorkItem, PublicationScope.Global);
        //                }
        //                if (_tmpfrm.LBIzabir.SelectedItem.ToString() == "Povrat robe")
        //                {

        //                    report = new PovratRobe(_entity);
        //                    WorkItem.EventTopics[EventTopicNames.PrikaziIzvjestaj].Fire(this, new EventArgs<object, string>(report, String.Format("Povrat robe {0}", _entity.Oznaka)), WorkItem, PublicationScope.Global);


        //                }

        //            }
        //            break;
             
        //        case (int)DokumentTipList.Rezervacija:
        //            //EditorClass = typeof(RezervacijaView);
        //            break;
        //        case (int)DokumentTipList.Zapisnik_o_promjeni_cijene:
        //            report = new rptXtraPromjenaCijene(_entity);
        //            WorkItem.EventTopics[EventTopicNames.PrikaziIzvjestaj].Fire(this, new EventArgs<object, string>(report, String.Format("Promjena cijene{0}", _entity.Oznaka)), WorkItem, PublicationScope.Global);
        //            break;
        //        case (int)DokumentTipList.Racun:
        //            report = new RacunOtpremnica(_entity);
        //            WorkItem.EventTopics[EventTopicNames.PrikaziIzvjestaj].Fire(this, new EventArgs<object, string>(report, String.Format("Račun {0}", _entity.Oznaka)), WorkItem, PublicationScope.Global);
        //            break;
        //        case (int)DokumentTipList.Racun_storno:
        //            report = new RacunOtpremnicaOK(_entity);
        //            WorkItem.EventTopics[EventTopicNames.PrikaziIzvjestaj].Fire(this, new EventArgs<object, string>(report, String.Format("Račun-OK {0}", _entity.Oznaka)), WorkItem, PublicationScope.Global);
        //            break;
        //        case (int)DokumentTipList.Racun_otpremnica:
        //            report = new RacunOtpremnica(_entity);
        //           // report = new rptXtraPonuda(_entity);
        //            WorkItem.EventTopics[EventTopicNames.PrikaziIzvjestaj].Fire(this, new EventArgs<object, string>(report, String.Format("Račun otpremnica {0}", _entity.Oznaka)), WorkItem, PublicationScope.Global);
        //            break;
        //        case (int)DokumentTipList.Racun_otpremnica_storno:
        //            report = new RacunOtpremnicaOK(_entity);
        //            WorkItem.EventTopics[EventTopicNames.PrikaziIzvjestaj].Fire(this, new EventArgs<object, string>(report, String.Format("Račun-otpremnica OK {0}", _entity.Oznaka)), WorkItem, PublicationScope.Global);
        //            break;
        //        case (int)DokumentTipList.Ponuda:
        //            report = new RacunOtpremnica(_entity);
        //            report.Name = "PonudaIspis";
        //            WorkItem.EventTopics[EventTopicNames.PrikaziIzvjestaj].Fire(this, new EventArgs<object, string>(report, String.Format("Ponuda {0}", _entity.Oznaka)), WorkItem, PublicationScope.Global);
        //            break;
        //        case (int)DokumentTipList.Ponuda_storno:
        //            report = new RacunOtpremnica(_entity);
        //            report.Name = "PonudaIspis";
        //            WorkItem.EventTopics[EventTopicNames.PrikaziIzvjestaj].Fire(this, new EventArgs<object, string>(report, String.Format("Storno ponude {0}", _entity.Oznaka)), WorkItem, PublicationScope.Global);
        //            break;
        //        case (int)DokumentTipList.Predračun:
        //            report = new RacunOtpremnica(_entity);
        //            report.Name = "PredračunIspis";
        //            WorkItem.EventTopics[EventTopicNames.PrikaziIzvjestaj].Fire(this, new EventArgs<object, string>(report, String.Format("Predračun {0}", _entity.Oznaka)), WorkItem, PublicationScope.Global);
        //            break;
        //        case (int)DokumentTipList.Predračun_storno:
        //            report = new RacunOtpremnica(_entity);
        //            report.Name = "PredračunStornoIspis";
        //            WorkItem.EventTopics[EventTopicNames.PrikaziIzvjestaj].Fire(this, new EventArgs<object, string>(report, String.Format("Storno predračuna {0}", _entity.Oznaka)), WorkItem, PublicationScope.Global);
        //            break;
        //        case (int)DokumentTipList.Racun_tranzitni:
        //            report = new RacunOtpremnica(_entity);
        //            report.Name = "RačuntranzitniIspis";
        //            WorkItem.EventTopics[EventTopicNames.PrikaziIzvjestaj].Fire(this, new EventArgs<object, string>(report, String.Format("Račun tranzitni {0}", _entity.Oznaka)), WorkItem, PublicationScope.Global);
        //            break;
        //        case (int)DokumentTipList.Racun_tranzitni_storno:
        //            report = new RacunOtpremnicaOK(_entity);
        //            report.Name = "RačuntranzitniStornoIspis";
        //            WorkItem.EventTopics[EventTopicNames.PrikaziIzvjestaj].Fire(this, new EventArgs<object, string>(report, String.Format("Račun tranzitni storno {0}", _entity.Oznaka)), WorkItem, PublicationScope.Global);
        //            break;
        //        case (int)DokumentTipList.Izdatnica:
        //            report = new IzdatnicaIspis(_entity);
        //            WorkItem.EventTopics[EventTopicNames.PrikaziIzvjestaj].Fire(this, new EventArgs<object, string>(report, String.Format("Izdatnica {0}", _entity.Oznaka)), WorkItem, PublicationScope.Global);
        //            break;
        //        case (int)DokumentTipList.Izdatnica_storno:
        //            report = new IzdatnicaIspisStorno(_entity);
        //            WorkItem.EventTopics[EventTopicNames.PrikaziIzvjestaj].Fire(this, new EventArgs<object, string>(report, String.Format("Izdatnica storno {0}", _entity.Oznaka)), WorkItem, PublicationScope.Global);
        //            break;
        //        case (int)DokumentTipList.Racun_usluga:
        //            report = new RacunUsluga(_entity);
        //            WorkItem.EventTopics[EventTopicNames.PrikaziIzvjestaj].Fire(this, new EventArgs<object, string>(report, String.Format("Račun usluga {0}", _entity.Oznaka)), WorkItem, PublicationScope.Global);
        //            break;
        //        case (int)DokumentTipList.Racun_usluga_storno:
        //            report = new RacunUslugaStorno(_entity);
        //            WorkItem.EventTopics[EventTopicNames.PrikaziIzvjestaj].Fire(this, new EventArgs<object, string>(report, String.Format("Račun usluga storno {0}", _entity.Oznaka)), WorkItem, PublicationScope.Global);
        //            break;
        //        case (int)DokumentTipList.Račun_MP:
        //            report = new RacunMPIspis(_entity);
        //            WorkItem.EventTopics[EventTopicNames.PrikaziIzvjestaj].Fire(this, new EventArgs<object, string>(report, String.Format("Račun maloprodajni {0}", _entity.Oznaka)), WorkItem, PublicationScope.Global);
        //            break;
        //        case (int)DokumentTipList.Račun_MP_storno:
        //            report = new RacunMPStornoIspis(_entity);
        //            WorkItem.EventTopics[EventTopicNames.PrikaziIzvjestaj].Fire(this, new EventArgs<object, string>(report, String.Format("Račun maloprodajni storno {0}", _entity.Oznaka)), WorkItem, PublicationScope.Global);
        //            break;
        //        case (int)DokumentTipList.Revers:
        //            report = new ReversIspis(_entity);
        //            WorkItem.EventTopics[EventTopicNames.PrikaziIzvjestaj].Fire(this, new EventArgs<object, string>(report, String.Format("Revers {0}", _entity.Oznaka)), WorkItem, PublicationScope.Global);
        //            break;
        //        case (int)DokumentTipList.Povrat_reversa:
        //            report = new ReversIspis(_entity);
        //            WorkItem.EventTopics[EventTopicNames.PrikaziIzvjestaj].Fire(this, new EventArgs<object, string>(report, String.Format("Povrat reversa {0}", _entity.Oznaka)), WorkItem, PublicationScope.Global);
        //            break;
        //        default:
        //            break;

        //    }

        //}



    }
}
